<template>
  <div id="app-container" style="padding:30px;">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="ManQuery.name" placeholder="姓名" />
      </el-form-item>
      <el-button type="primary" @click="querys()">查询</el-button>
      <el-button type="primary" @click="reset()">清空</el-button>
      <router-link :to="'/copyrightin/copyrightin/list/'">
        <el-button type="primary">返回</el-button>
      </router-link>
      <router-link :to="'/copyrightin/copyrightin/ManCreate'">
        <el-button type="primary">添加客户</el-button>
      </router-link>
    </el-form>
  <el-table :data="manList" border fit highlight-current-row>
    <el-table-column label="序号" width="70" align="center">
      <template slot-scope="scope">
        {{ (pageNo - 1) * pageSize + scope.$index + 1 }}
      </template>
    </el-table-column>
    <el-table-column prop="copyRight.copyrightName" label="版权名" width="80" />
    <el-table-column prop="name" label="姓名"/>
    <el-table-column prop="sex" label="性别" />
    <el-table-column prop="birthday" label="出生日期" />
    <el-table-column prop="telephone" label="手机号" />
    <el-table-column prop="phone" label="座机号" />
    <el-table-column prop="email" label="邮箱" />
    <el-table-column prop="qq" label="qq" />
    <el-table-column prop="address" label="公司地址" />
    <el-table-column prop="remark" label="备注" />
    <el-table-column prop="duty" label="职务" />
    <el-table-column label="操作" align="center">
      <template slot-scope="scope">
        <el-button type="danger" size="mini" @click="deleteManById(scope.row.id)">删除</el-button>
        <router-link :to="'/copyrightin/copyrightin/updateMan/'+scope.row.id">
          <el-button type="primary" size="mini" >修改</el-button>
        </router-link>
      </template>
    </el-table-column>
  </el-table>
  </div>
</template>

<script>
  import copyrightin from '@/api/copyrightin/copyrightin.js'
    export default {
      data() {
        return {
          manList: null,
          ManQuery: {},
          total: 0,
          pageNo: 1,
          pageSize: 10,
          currentTime: ''
        }
      },
      created() {
        this.querys()
        this.init()
      },
      methods: {
        init() { // ## 初始化
          // ## 判断路径中是否存在id值
          if (this.$route.params && this.$route.params.id) {
            // ## 从路径中获取id值
            const id = this.$route.params.id
            this.ManQuery.copyrightId=id
            // ##调用回显方法
            // this.getManById(id)
          }
        },
        querys(pageNo = 1) {
          this.pageNo = pageNo
          copyrightin.findPageCopyrightinMan(this.pageNo, this.pageSize, this.ManQuery)
            .then(response => {
              this.manList = response.data.items
              this.total = response.data.total
              this.currentTime = this.format(new Date(), 'yyyy-MM-dd HH:mm:ss')
            })
        },
        format(date, fmt) { // ## 格式化日期
          let o = {
            'M+': date.getMonth() + 1, // ## 月份
            'd+': date.getDate(), // ## 日
            'H+': date.getHours(), // ## 小时
            'm+': date.getMinutes(), // ## 分
            's+': date.getSeconds(), // ## 秒
            'q+': Math.floor((date.getMonth() + 3) / 3), // ## 季度
            'S': date.getMilliseconds() // ## 毫秒
          }
          if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
          for (let k in o)
            if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
          return fmt
        },
        reset() {
          this.ManQuery = {}
          this.querys()
        },
        findAll(){

        },

        deleteManById(id) { // ## 删除书籍
          this.$confirm('此操作将永久删除该书籍记录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            copyrightin.deleteManById(id)
              .then(response => {
                this.querys()
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                })
              })
          })
        }
      }
    }
</script>

<style scoped>

</style>
